package com.geralt.im.entrance;

import java.awt.EventQueue;
import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;

import javax.swing.JFrame;
import javax.swing.JOptionPane;

import com.geralt.im.client.IMClient;
import com.geralt.im.command.Command;
import com.geralt.im.commandparse.impl.RpParser;
import com.geralt.im.gui.ClientGUI;
import com.geralt.im.gui.LoginUI;
import com.geralt.im.gui.RegisterGUI;
import com.geralt.im.gui.UIHolder;
import com.geralt.im.model.Customer;
import com.geralt.im.model.Message;
import com.geralt.im.uicontroller.IUIListener;

public class Entrance {

	public static Customer customer;
	public static IMClient client;
	public static String reciever;
	public static boolean onLogin = false;
	public static void main(String[] args) {
		try {
			Socket socket = new Socket("localhost", 10102);

			client = new IMClient(socket);
		} catch (Exception e) {
			JOptionPane.showMessageDialog(null,"can not connect server", "Error",
					JOptionPane.ERROR_MESSAGE);
		}
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					JFrame.setDefaultLookAndFeelDecorated(true);
					UIHolder holder = new UIHolder();
					
					ClientGUI clientGui = new ClientGUI();
					clientGui.setVisible(false);
					LoginUI loginGui = new LoginUI();
					loginGui.addIUIListener(holder);
					loginGui.setVisible(false);
					RegisterGUI registerGUI= new RegisterGUI();
					registerGUI.setVisible(false);
					holder.addUI("chat", clientGui);
					holder.addUI("login", loginGui);
					holder.addUI("register", registerGUI);
					holder.showUI("login");
					RpParser rpParser = RpParser.getInstance();
					for (Command command : rpParser.keyCommandMap.values()) {
						command.resgiestObserver(clientGui);
						command.resgiestObserver(loginGui);
						command.resgiestObserver(registerGUI);
					}
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});

	}

	
}
